<?php
require_once("inc.public.php");
$new_uid = 1;
$total_cp = 10500;
				if($total_cp>0){
					$trade_cp = $total_cp/5;
					$sum_cp = 0;
					
					for($i=1;$i<=5;$i++){
						$total_sales = @mysql_result(mysql_query("SELECT sum(total_unit*buy_price) as total_sales FROM $db->share"), 0);
						
						$total_sales += $sum_cp + 0.1;						
						if($i==5){
							$trade_cp = $total_cp - $sum_cp;
							print_r($sum_cp);
						}
						
						switch($total_sales){
							case ($total_sales < 1000000):
								$unit_price = 1;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>1000000){
									$balance_cp = 1000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 1.5;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 3000000):
								$unit_price = 1.5;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>3000000){
									$balance_cp = 3000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 2;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 6000000):
								$unit_price = 2;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>6000000){
									$balance_cp = 6000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 3;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 10000000):
								$unit_price = 3;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>10000000){
									$balance_cp = 10000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 4;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 15000000):
								$unit_price = 4;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>15000000){
									$balance_cp = 15000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 5;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 20000000):
								$unit_price = 5;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>20000000){
									$balance_cp = 20000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 6;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 25000000):
								$unit_price = 6;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>25000000){
									$balance_cp = 25000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 7;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 30000000):
								$unit_price = 7;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>30000000){
									$balance_cp = 30000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 8;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 35000000):
								$unit_price = 8;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>35000000){
									$balance_cp = 35000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 9;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 40000000):
								$unit_price = 9;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>40000000){
									$balance_cp = 40000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 10;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 45000000):
								$unit_price = 10;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>45000000){
									$balance_cp = 45000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 11;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							case ($total_sales < 50000000):
								$unit_price = 11;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								if($total_sales+$trade_cp>50000000){
									$balance_cp = 50000000 - $total_sales;		
									$total_unit_share = floor($balance_cp/$unit_price);				
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
									
									$total_trade_cp = $total_unit_share*$unit_price;
									$balance_trade_cp = $trade_cp - $total_trade_cp;
									
									$unit_price = 12;
									$total_unit_share = floor($balance_trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}else{
									$total_unit_share = floor($trade_cp/$unit_price);
									print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
									$sum_cp += $total_unit_share*$unit_price;
								}
								break;
							default: print_r($total_sales);
								$unit_price = 12;							
								$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30)+30, date("Y")));
								
								$total_unit_share = floor($trade_cp/$unit_price);
								print_r("<br>INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$new_uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
								$sum_cp += $total_unit_share*$unit_price;
								break;
						}
					}
				}

print_r('finish');
exit;
?>